home *** CD-ROM | disk | FTP | other *** search
/ mail.altrad.com / 2015.02.mail.altrad.com.tar / mail.altrad.com / TEST / office german / PROPLUS.WW / PROPLSWW.CAB / MSORES.DLL / 226 / 657 < prev    next >
Extensible Markup Language  |  2006-10-26  |  8KB  |  163 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. ***************************************************************************
  4.     dlcxsd2template.xslt
  5.     Transform that creates a template from an XSD.
  6. *************************************************************************** -->
  7. <xsl:stylesheet 
  8.     version="1.0"
  9.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  10.     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  11.     xmlns:ma="http://schemas.microsoft.com/office/2006/metadata/properties/metaAttributes"
  12.     xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
  13.     xmlns:ct="http://schemas.microsoft.com/office/2006/metadata/contentType"
  14.     xmlns:dms="http://schemas.microsoft.com/office/2006/documentManagement/types"
  15.     xmlns:out = "output.xsl">
  16.     <xsl:output method="xml" encoding="utf-8" indent="yes" />
  17.     <xsl:namespace-alias stylesheet-prefix="out" result-prefix="xsl" />
  18.     <!-- Properties Root namespace -->
  19.     <xsl:variable name="rootNSUri">http://schemas.microsoft.com/office/2006/metadata/propertiesRoot</xsl:variable>
  20.     <xsl:variable name="rootPrefix">pr</xsl:variable>
  21.     <!-- Core properties namespace -->
  22.     <xsl:variable name="coreNSUri">http://schemas.openxmlformats.org/package/2006/metadata/core-properties</xsl:variable>
  23.     <xsl:variable name="corePrefix">core</xsl:variable>
  24.     <xsl:variable name="dctermsNSUri">http://purl.org/dc/terms/</xsl:variable>
  25.     <xsl:variable name="dctermsPrefix">dcterms</xsl:variable>
  26.     <xsl:variable name="dcNSUri">http://purl.org/dc/elements/1.1/</xsl:variable>
  27.     <xsl:variable name="dcPrefix">dc</xsl:variable>
  28.     <xsl:variable name="dcmitypeNSUri">http://purl.org/dc/dcmitype/</xsl:variable>
  29.     <xsl:variable name="dcmitypePrefix">dcmitype</xsl:variable>
  30.     <!-- WSS properties namespace -->
  31.     <xsl:variable name="propsNSUri" select="/ct:contentTypeSchema/xsd:schema[@ma:root='true']/@targetNamespace" />
  32.     <xsl:variable name="propsPrefix">p</xsl:variable>
  33.     <!-- XSI namespace -->
  34.     <xsl:variable name="xsiNSUri">http://www.w3.org/2001/XMLSchema-instance</xsl:variable>
  35.     <xsl:variable name="baseXPath">documentManagement/</xsl:variable>
  36.     <!-- WSS property namespaces -->    
  37.     <xsl:variable name="nsDecls" select="/ct:contentTypeSchema/xsd:schema[@ma:root = 'true']/namespace::*[local-name() != 'xml']" />
  38.     <!-- Main template -->
  39.     <xsl:template match="/ct:contentTypeSchema | /xsd:schema">
  40.         <!-- Processing instructions -->
  41.         <xsl:processing-instruction name="mso-infoPathSolution">
  42.             <xsl:text>solutionVersion="1.0.0.1" productVersion="12.0.2303" PIVersion="1.0.0.0" href="template.xml"</xsl:text>
  43.         </xsl:processing-instruction>
  44.         <xsl:processing-instruction name="mso-application"><xsl:text>progid="InfoPath.Document"</xsl:text></xsl:processing-instruction>
  45.         <!-- Root properties node -->
  46.         <xsl:element name="{$rootPrefix}:properties" namespace="{$rootNSUri}">
  47.             <xsl:call-template name="NamespaceDeclarations" />
  48.             <xsl:choose>
  49.                 <xsl:when test="/ct:contentTypeSchema">
  50.                     <!-- Core properties node -->
  51.                     <xsl:element name="{$corePrefix}:coreProperties" namespace="{$coreNSUri}">
  52.                         <xsl:apply-templates mode="core" select="xsd:schema[@targetNamespace = $coreNSUri]/xsd:complexType/*/xsd:element"/>
  53.                     </xsl:element>
  54.                     <!-- WSS properties node -->
  55.                     <xsl:element name="{$propsPrefix}:properties" namespace="{$propsNSUri}">
  56.                         <xsl:element name="documentManagement">
  57.                             <xsl:for-each select="xsd:schema[(not(@ma:root) or @ma:root = 'false') and @targetNamespace != $coreNSUri]/xsd:element">
  58.                                 <xsl:sort select="@ma:index" data-type="number" />
  59.                                 <xsl:call-template name="wss"/>
  60.                             </xsl:for-each>
  61.                         </xsl:element>
  62.                     </xsl:element>
  63.                 </xsl:when>
  64.                 <xsl:otherwise>
  65.                     <!-- Core properties node -->
  66.                     <xsl:element name="{$corePrefix}:coreProperties" namespace="{$coreNSUri}">
  67.                         <xsl:apply-templates mode="core" select="xsd:complexType/*/xsd:element"/>
  68.                     </xsl:element>
  69.                 </xsl:otherwise>
  70.             </xsl:choose>
  71.         </xsl:element>
  72.     </xsl:template>
  73.     <!-- Namespace declarations -->
  74.     <xsl:template name="NamespaceDeclarations">
  75.         <xsl:for-each select="$nsDecls">
  76.             <xsl:attribute name="{local-name()}:_" namespace="{.}" />
  77.         </xsl:for-each>
  78.     </xsl:template>
  79.     <!-- Core property elements -->
  80.     <xsl:template match="xsd:element" mode="core">
  81.         <xsl:choose>
  82.             <xsl:when test="starts-with(@ref, concat($dctermsPrefix, ':'))">
  83.                 <xsl:element name="{@ref}" namespace="{$dctermsNSUri}" />
  84.             </xsl:when>
  85.             <xsl:when test="starts-with(@ref, concat($dcPrefix, ':'))">
  86.                 <xsl:element name="{@ref}" namespace="{$dcNSUri}" />
  87.             </xsl:when>
  88.             <xsl:when test="starts-with(@ref, concat($dcmitypePrefix, ':'))">
  89.                 <xsl:element name="{@ref}" namespace="{$dcmitypeNSUri}" />
  90.             </xsl:when>
  91.             <xsl:otherwise>
  92.                 <xsl:element name="{$corePrefix}:{@name}" namespace="{$coreNSUri}" />
  93.             </xsl:otherwise>
  94.         </xsl:choose>
  95.     </xsl:template>
  96.     <!-- WSS property elements -->
  97.     <xsl:template name="wss">
  98.         <xsl:variable name="elementNSUri" select="current()/ancestor::xsd:schema/@targetNamespace" />
  99.         <xsl:variable name="elementPrefix" select="local-name($nsDecls[. = $elementNSUri])" />
  100.         <xsl:variable name="elementQName">
  101.             <xsl:value-of select="$elementPrefix" />
  102.             <xsl:text>:</xsl:text>
  103.             <xsl:value-of select="@name" />
  104.         </xsl:variable>
  105.         <xsl:choose>
  106.             <xsl:when test="xsd:simpleType">
  107.                 <xsl:element name="{$elementQName}" namespace="{$elementNSUri}">
  108.                     <xsl:choose>
  109.                         <!-- write default value, except 'today' for datetime fields -->
  110.                         <xsl:when test="@ma:default and (@ma:default != '[today]' or xsd:simpleType/xsd:restriction[@base != 'dms:DateTime'])">
  111.                             <xsl:choose>
  112.                                 <xsl:when test="xsd:simpleType/xsd:restriction[@base='dms:Boolean']">
  113.                                     <xsl:value-of select="boolean(@ma:default)" />
  114.                                 </xsl:when>
  115.                                 <xsl:otherwise>
  116.                                     <xsl:value-of select="@ma:default" />
  117.                                 </xsl:otherwise>
  118.                             </xsl:choose>
  119.                         </xsl:when>
  120.                         <xsl:when test="@nillable='true'">
  121.                             <xsl:attribute name="xsi:nil" namespace="{$xsiNSUri}">true</xsl:attribute>
  122.                         </xsl:when>
  123.                     </xsl:choose>
  124.                 </xsl:element>
  125.             </xsl:when>
  126.             <xsl:when test="xsd:complexType">
  127.                 <xsl:choose>
  128.                     <xsl:when test="xsd:complexType/xsd:complexContent/*[@base='dms:URL']">
  129.                         <xsl:element name="{$elementQName}" namespace="{$elementNSUri}">
  130.                             <xsl:element name="{$elementPrefix}:Url" namespace="{$elementNSUri}">
  131.                                 <xsl:if test="@nillable[. ='true']">
  132.                                     <xsl:attribute name="xsi:nil" namespace="{$xsiNSUri}">true</xsl:attribute>
  133.                                 </xsl:if>
  134.                             </xsl:element>
  135.                             <xsl:element name="{$elementPrefix}:Description" namespace="{$elementNSUri}" />
  136.                         </xsl:element>
  137.                     </xsl:when>
  138.                     <xsl:when test="xsd:complexType/xsd:complexContent/*/@base[.='dms:MultiChoice' or .='dms:MultiChoiceFillIn' or .='dms:MultiChoiceLookup']">
  139.                         <xsl:element name="{$elementQName}" namespace="{$elementNSUri}">
  140.                             <xsl:element name="{$elementPrefix}:Value" namespace="{$elementNSUri}">
  141.                                 <xsl:value-of select="@ma:default" />
  142.                             </xsl:element>
  143.                         </xsl:element>
  144.                     </xsl:when>
  145.                     <xsl:when test="xsd:complexType/xsd:complexContent/*/@base[.='dms:User' or .='dms:UserMulti']">
  146.                         <xsl:element name="{$elementQName}" namespace="{$elementNSUri}">
  147.                             <xsl:element name="{$elementPrefix}:UserInfo" namespace="{$elementNSUri}">
  148.                                 <xsl:element name="{$elementPrefix}:DisplayName" namespace="{$elementNSUri}" />
  149.                                 <xsl:element name="{$elementPrefix}:AccountId" namespace="{$elementNSUri}">
  150.                                     <xsl:if test="@nillable[. ='true']">
  151.                                         <xsl:attribute name="xsi:nil" namespace="{$xsiNSUri}">true</xsl:attribute>
  152.                                     </xsl:if>
  153.                                 </xsl:element>
  154.                                 <xsl:element name="{$elementPrefix}:AccountType" namespace="{$elementNSUri}" />
  155.                             </xsl:element>
  156.                         </xsl:element>
  157.                     </xsl:when>
  158.                 </xsl:choose>
  159.             </xsl:when>
  160.         </xsl:choose>
  161.     </xsl:template>
  162. </xsl:stylesheet>
  163.